package com.example.business_oa.controller;


import cn.hutool.core.date.DateUtil;
import com.example.business_oa.service.*;
import com.example.comment_oa.pojos.Amount;
import com.example.comment_oa.pojos_vo.FybxVo;
import com.example.comment_oa.pojos_vo.flowableVo.taskVo;
import com.example.comment_oa.response.AjaxResponse;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/businessOa")
public class ShenPiQingJiaController {

    @Resource
    ShenPiQingJiaService shenPiQingJiaService;
    @Resource
    HoliService holiService;
    @Resource
    HyJobService hyJobService;
    @Resource
    ZfPositiveService positiveService;
    @Resource
    ZfDimissionService dimissionService;
    @Resource
    PosService posService;
    @Resource
    FybxService fybxService;

    @PostMapping("/tongyiqingjia")
    public AjaxResponse tongyiqingjia(@RequestBody taskVo taskVo){
        System.err.println(taskVo);

        if(taskVo.getApprovd()){
            holiService.yesBusi(taskVo.getBianhao(),taskVo.getLingdao());
        }
        shenPiQingJiaService.QingJiaShenPiTongYi(taskVo);
        return AjaxResponse.success();
    }

    @PostMapping("/jujueqingjia")
    public AjaxResponse QingJiaShenPiJuJue(@RequestBody taskVo taskVo){
        System.err.println(taskVo);
        if(taskVo.getApprovd()==false){
            holiService.noBusi(taskVo.getBianhao(),taskVo.getLingdao());
        }
        shenPiQingJiaService.QingJiaShenPiJuJue(taskVo);
        return AjaxResponse.success();
    }


    @PostMapping("/tongyixuqiu")
    public AjaxResponse tongyixuqiu(@RequestBody taskVo taskVo){
        System.err.println(taskVo);
        int i = hyJobService.jobStatus(taskVo.getLingdao(), taskVo.getBianhao());
        shenPiQingJiaService.tongyiXuQIu(taskVo);
        return AjaxResponse.success();
    }

    @PostMapping("/jujuexuqiu")
    public AjaxResponse jujuexuqiu(@RequestBody taskVo taskVo){
        System.err.println(taskVo);
        int i = hyJobService.jobStatuss(taskVo.getLingdao(), taskVo.getBianhao());
        shenPiQingJiaService.jujueXuQIu(taskVo);
        return AjaxResponse.success();
    }


    @PostMapping("/tongyizhuanzheng")
    public AjaxResponse tongyizhuanzheng(@RequestBody taskVo taskVo){
        int i = positiveService.posState(taskVo.getLingdao(), taskVo.getBianhao());
        shenPiQingJiaService.tongyiXuQIu(taskVo);
        return AjaxResponse.success();
    }

    @PostMapping("/jujuezhuanzheng")
    public AjaxResponse jujuezhuanzheng(@RequestBody taskVo taskVo){
        int i = positiveService.posStates(taskVo.getLingdao(), taskVo.getBianhao());
        shenPiQingJiaService.tongyiXuQIu(taskVo);
        return AjaxResponse.success();
    }


    @PostMapping("/tongyilizhi")
    public AjaxResponse tongyilizhi(@RequestBody taskVo taskVo){
        int i = dimissionService.dimState(taskVo.getLingdao(), taskVo.getBianhao());
        shenPiQingJiaService.tongyiXuQIu(taskVo);
        return AjaxResponse.success();
    }

    @PostMapping("/jujuelizhi")
    public AjaxResponse jujuelizhi(@RequestBody taskVo taskVo){
        int i = dimissionService.dimStates(taskVo.getLingdao(), taskVo.getBianhao());
        shenPiQingJiaService.tongyiXuQIu(taskVo);
        return AjaxResponse.success();
    }

    @PostMapping("/tongyidingdan")
    public AjaxResponse tongyidingdan(@RequestBody taskVo taskVo){

        posService.upPos(taskVo);

        shenPiQingJiaService.tongyiXuQIu(taskVo);

        return AjaxResponse.success();
    }


    @PostMapping("/jujuedingdan")
    public AjaxResponse jujuedingdan(@RequestBody taskVo taskVo){

        posService.upPos(taskVo);

        shenPiQingJiaService.tongyiXuQIu(taskVo);


        return AjaxResponse.success();
    }


    @PostMapping("/tognyibaoxiao")
    public AjaxResponse tognyibaoxiao(@RequestBody taskVo taskVo){
        List<Amount> list=fybxService.spsj(taskVo.getBianhao());
        Date date = new Date(String.valueOf(list.get(0).getAmountXb().getCdqj()));
        String year = DateUtil.format(date, "yyyy");
        String month = DateUtil.format(date, "MM");
        fybxService.updatefazt(list.get(0).getAmountXb().getInvoicePhone());
        //减少剩余额
        fybxService.updateSy(list.get(0).getAmountMoney(),year,month,list.get(0).getDeptName(),list.get(0).getAmountXb().getBxkm());
        //修改报销流程状态
        fybxService.updatebxState(0,taskVo.getBianhao());


        shenPiQingJiaService.tongyiXuQIu(taskVo);

        return AjaxResponse.success();
    }


    @PostMapping("/jujuebaoxiao")
    public AjaxResponse jujuebaoxiao(@RequestBody taskVo taskVo){
        List<Amount> list=fybxService.spsj(taskVo.getBianhao());
        Date date = new Date(String.valueOf(list.get(0).getAmountXb().getCdqj()));
        String year = DateUtil.format(date, "yyyy");
        String month = DateUtil.format(date, "MM");

        fybxService.csyszj(list.get(0).getAmountMoney(),year,month,list.get(0).getDeptName(),list.get(0).getAmountXb().getBxkm());
        //修改报销流程状态
        fybxService.updatebxState(2,taskVo.getBianhao());


        shenPiQingJiaService.tongyiXuQIu(taskVo);


        return AjaxResponse.success();
    }





}
